#include <header.h>

pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;

void *run(void *arg){

    pthread_mutex_lock(&lock);
    printf("thread begin\n");

    time_t now = time(NULL);
    struct timespec time_out = {now + 10, 0};

    // 唤醒后会拿锁
    pthread_cond_timedwait(&cond, &lock, &time_out);

    printf("thread wake\n");
    pthread_mutex_unlock(&lock);
    return (void*)0;
}



int main(int argc, char* argv[]){
    pthread_t p;
    pthread_create(&p, NULL, run, NULL);

    sleep(1);
    pthread_mutex_lock(&lock);
    sleep(10);
    pthread_mutex_unlock(&lock);

    pthread_join(p, NULL);
	return 0;
}